package com.youan.log.modules.audit.wrapper;

import com.youan.log.common.entity.ThreadTaskProgress;
import com.youan.log.common.threadtask.ThreadTaskUtils;
import com.youan.log.modules.audit.dto.ImportRecordDTO;
import com.youan.log.modules.audit.entity.ImportRecord;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;

import java.util.Objects;

public class ImportRecordWrapper extends BaseEntityWrapper<ImportRecord, ImportRecordDTO> {

    public static ImportRecordDTO build(ImportRecord entity) {
        return new ImportRecordWrapper().entityVO(entity);
    }

    @Override
    public ImportRecordDTO entityVO(ImportRecord entity) {
        ImportRecordDTO result = Objects.requireNonNull(BeanUtil.copy(entity, ImportRecordDTO.class));
        ThreadTaskProgress progress = ThreadTaskUtils.getThreadTaskProgress(entity.getTaskId());
        result.setThreadTaskProgress(progress);
        return result;
    }
}
